Workflow.extend( {
    /**
     * 获取任务列表
     */
    listUserTask: function(workflowName) {
        $("#WorkflowName").val(workflowName);
        $("#TaskWorkflowDef").find("option").each(function() {
            if($(this).val() == workflowName) {
                this.selected = true;
            }
        });
        $("#TaskWorkflowState").find("option").each(function() {
            if($(this).val() == workflowName) {
                this.selected = true;
            }
        });
        //TODO 设置下拉列表 TaskWorkflowDef 和 TaskWorkflowState
        
        //
        setHideShow("WorkflowTasks");
        Workflow.Current_View = "WorkflowTasks";
        
        //
        workflowTaskGrid = new dhtmlXGridObject("WorkflowTasksTableDiv");
        workflowTaskGrid.setImagePath("../images/dhtmlxgrid/");
        workflowTaskGrid.setHeader(" ,任务名,流程名,状态,执行,图例");
        workflowTaskGrid.setInitWidths("40,150,250,50,60,60");
        workflowTaskGrid.setColAlign("center,left,left,center,center,center");
        workflowTaskGrid.setColTypes("ch,ro,ro,ro,link,link");
        workflowTaskGrid.setSkin("light");
        workflowTaskGrid.init();      
        workflowTaskGrid.loadXML("../xmlRes?s=workflowAction&act=listUserTask&wf=" + workflowName); 
        //var params = {act:"listUserTask", wf: workflowName};
        //Workflow.Ajax_Response = "listUserTaskResponse";
        //this.ajaxAction(params);
    },
    
    
    /**
     * 执行 Task
     */
    setExecuteTask: function(taskId) {
        $("#TaskId").val(taskId);
        this.getExecuteTaskContent(taskId);
        $("#ProcActionCnt").html("loading ......");
    },
    getExecuteTaskContent: function(taskId) {
        var params = {act:"getTaskContent", tid: taskId, start: "1"};
        //
        Workflow.Ajax_Response = "getExecuteTaskContentResponse";
        this.ajaxAction(params);
    },
    getExecuteTaskContentResponse: function(xmlData) {
        var xmlDoc = parseXML(xmlData);
        var content = xmlDoc.selectNodes("//task-content/form-content");
        if(content.length == 1) {
            $("#WorkflowContent").val(getXMLNodeValue(content[0]));
        } else {
            $("#WorkflowContent").val("");
        }
        var transitions = xmlDoc.selectNodes("//task-content/transitions/transition");
        $("#ProcActionCnt").html("");
        if(transitions.length == 0) {
            $("#ProcActionCnt").append("<a href='javascript:' onclick=''>执行</a>");
        } else {
            for(var i = 0; i < transitions.length; i++) {
                var transition = getXMLNodeValue(transitions[i]);
                var tmpStr = "<a href='javascript:' onclick='Workflow.executeTask(\"" 
                    + transition + "\")'>" + transition + "</a> "
                $("#ProcActionCnt").append(tmpStr);
            }
        }
        //$("#ProcActionCnt").append("<a href='javascript:' onclick=''>取消</a>");
    },
    executeTask: function(nextTask) {
        var taskId = $("#TaskId").val();
        var workflowContent = $('#WorkflowContent').val();
        var params = {act:"processTask", tc: workflowContent, tid: taskId, nt: nextTask};
        //
        Workflow.Ajax_Response = "executeTaskResponse";
        this.ajaxAction(params);
    }, 
    executeTaskResponse: function(xmlData) {
        alert(xmlData);
    }
});
